<?php
//redis时间到期销毁执行
function run_task($redis, $pattern, $chan, $key)
{
    // 
    // echo "Pattern: $pattern\n";
    // echo "Channel: $chan\n";
    // echo "Msg: $key\n";

    $data = json_decode(base64_decode($key),true);
    $domain = 'https://court.nyxxkj.com';
    if($data){
        file_put_contents('redis.txt',date('Y-m-d H:i:s__').$key.PHP_EOL,FILE_APPEND);
        switch ($data['type']) {
            case '1':
                //写需要执行的接口
                echo file_get_contents($domain.'/api/order/query_baochang_pay_order?order='.$data['order']);
                break;
            case '2':
                # code...
                break;
            default:
                # code...
                break;
        }
    }
    var_dump($data);
  

}


$redis = new \Redis();
//连接本地的 Redis 服务  可以更改自己的
$redis->connect("127.0.0.1", 6379);

$redis->setOption(\Redis::OPT_READ_TIMEOUT,-1);
echo "订阅任务消息监听..".PHP_EOL;
$redis->psubscribe(array('__keyevent@0__:expired'), 'run_task');

?>